<head>
  <meta charset=UTF-8>
</head>
<body>
<script type="text/javascript" src="jquery-3.1.1.js">
</script>
<script type="text/javascript">
//测试jQuery.support
document.writeln("浏览器是否支持创建XMLHttpRequest:"
  + $.support.ajax + "<br />");
//测试jQuery.support
document.writeln("XMLHttpRequest是否有withCredentials:"
  + $.support.cors + "<br />");
//去除字符串前后的空白
document.writeln("$.trim(' ddd');的结果是"
  + $.trim(" ddd") + "<br />");
//遍历数组
$.each(["java" , "ajax" , "java ee"] , function(index, val)
  {
    document.writeln("['java' , 'ajax', 'java ee']的第"
      + index + "个元素为:" + val + "<br />");
  }
);
//以指定函数过滤数组
var grepResult = $.grep(["java" , "ajax" , "java ee"]
  , function(val, index)
  {
    //当数组元素的字符个数大于5时被保留
    return val.length > 5;
  }
);
document.writeln("['java' , 'ajax' , 'java ee']中数组元素的"
  + "字符个数大于5的还有:"
  + grepResult + "<br />");
//以旧数组创建新数组
var mapResult = $.map(["java" , "ajax" , "java ee"]
  , function(val, index)
  {
    //将数组元素和索引值连缀在一起作为新的数组元素
    return val + index
  }
);
document.writeln("以['java' , 'ajax' , 'java ee']创建的新数组为:"
  + mapResult);
//创建div元素
var div = $("<div>aa<div>");
//以相同的两个div创建数组
var divArr = [div , div];
document.writeln("divArr.length的值为:" + divArr.length + "<br />");
//执行$.uniqueSort去除重复元素
document.writeln("$.uniqueSort(divArr).length的结果为:"
  + $.uniqueSort(divArr).length + "<br />");
var str = "aa";
//以两个相同的字符串创建数组
var strArr = [str , str];
document.writeln("strArr.length的值为:"
  + strArr.length + "<br />");
//执行$.uniqueSort去除重复元素
document.writeln("$.uniqueSort(strArr).length的结果为:"
  + $.uniqueSort(strArr).length + "<br />");
//解析JSON字符串
var result = $.parseJSON('[{"name":"孙悟空","age":500},'
  + '{"name":"白骨精","age":21}]');
for (var i = 0, len = result.length ; i < len ; i++)
{
  document.writeln("第" + i + "个角色的年龄是:"
    + result[i].name + ",年龄是:"
    + result[i].age + "<br/>");
}
</script>
</body>
